<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="../js/mui.min.js"></script>
    <link href="../css/mui.min.css" rel="stylesheet"/>
    <script src="../js/public.js"></script>
    <script src="../js/jquery.js"></script>
    <style>
    	/* 消息区域   */
    	.mission{width: 98%; margin:2rem 1%;}
    	.mission p{height: 2.5rem; line-height: 2.5rem; margin-bottom: 0.5rem; background-color: #FFF;}
    	.mission p a{font-size: 1rem;padding-left: 0.5rem; width: 70%;overflow: hidden;white-space: normal;text-overflow: ellipsis; color:#777777;}
		.mission p span{float: right;font-size: 1rem;width: 25%;overflow: hidden;white-space: normal;text-overflow: ellipsis; }
		.fl{float: left;}
    </style>
</head>
<body>
	<div id="pullrefresh" class="mui-content">
	    <div class="mui-content-padded mission" id="mission">
	    </div>
	</div>
</body>
<script type="text/javascript" charset="utf-8">
var user = JSON.parse(localStorage.getItem('$users')).account;
  	mui.init({
  		swipeBack: false,
		pullRefresh: {
			
			container: '#pullrefresh',
			down: {
				contentrefresh: '正在刷新...',
				callback: pulldownRefresh
			},
			up: {
				contentrefresh: '正在加载...',
				callback: pullupRefresh
			}
		}
  	});
  	//
  	function send(){
     	mui.ajax({
            type: "POST",
		    url: __PATH__+"index/news",
		    async: true,
		    data:{
		    	username:user
		    },
		    dataType: "json",
		    json: "jsoncallback",
		    timeout: 1000,
		    success: function(data) {
		    	console.log(data);
		    	mui.each(data,function(item,i){
			   	if(item<20){
			   		var html = '<p><input type="hidden" value="'+i.updatetime+'" class="updatetime"><input type="hidden" value="'+i.send_member+'" class="send_member"><input type="hidden" value="'+i.resourceName+'" class="resourceName"><input type="hidden" value="'+i.orderNo+'" class="orderNo"><input type="hidden" value="'+i.abnormal_name+'" class="abnormal_name"><input type="hidden" value="'+i.createtime+'" class="createtime"><input type="hidden" value="'+i.id+'" class="id"><a href="javascript:void(0);" class="fl p">'+i.resourceName+i.abnormal_name+'</a><span class="fr">'+i.updatetime+'</span></p>'
                    mui('#mission')[0].insertAdjacentHTML('afterbegin', html);
			   	} 	  
              });
		    },
		    error:function(xhr,type,errorThrown){
				mui.alert(xhr,'提示') 				
			}
		});
     };
     setTimeout("send()",200);
  	//
  	
  	mui('#mission').on('tap','p',function(){
  		var abnormal_name = $(this).children('.abnormal_name').val();
		var createtime = $(this).children('.createtime').val();
		var id = $(this).children('.id').val();
		var orderNo = $(this).children('.orderNo').val();
		var resourceName = $(this).children('.resourceName').val();
		var send_member = $(this).children('.send_member').val();
		var updatetime = $(this).children('.updatetime').val();
		mui.ajax({
            type: "POST",
		    url: __PATH__+"index/dialog_details",
		    async: true,
		    data:{
		    	username:user,
		    	id:id
		    },
		    dataType: "json",
		    json: "jsoncallback",
		    timeout: 1000,
		    success: function(data) {
		    	console.log(data);
		    },
		    error:function(xhr,type,errorThrown){
				mui.alert(xhr,'提示') 				
			}
		});
		mui.openWindow({
				url:"dialog_details.html",
				id:"dialog_details",
				style:{},
			   extras:{
			   	abnormal_name:abnormal_name,
			   	createtime:createtime,
			   	updatetime:updatetime,
			   	resourceName:resourceName,
			   	send_member:send_member,
			   	orderNo:orderNo
			   },
				show:{
					autoShow:true,
					aniShow:"slide-in-right",
					duration:100
				},
				waiting:{
					autoShow:true,
					title:"正在加载·····",
					options:{
		//				width:
		//				height:
					}
				}
		})
  	});
  	  /*
	   * 下拉刷新具体业务实现
	   */
	  function pulldownRefresh() 
	  {
	    setTimeout(function() 
	    { 
		      mui.ajax({
	            type: "POST",
			    url: __PATH__+"index/news",
			    async: true,
			    data:{
			    	username:user
			    },
			    dataType: "json",
			    json: "jsoncallback",
			    timeout: 1000,
			    success: function(data) {
			    	var dialog = data;
		            var cells = document.body.querySelectorAll('.mission p');
			        for(var i = cells.length, len = i + 1; i < len; i++){
			      	    var html = '<p><input type="hidden" value="'+data[i].updatetime+'" class="updatetime"><input type="hidden" value="'+data[i].send_member+'" class="send_member"><input type="hidden" value="'+data[i].resourceName+'" class="resourceName"><input type="hidden" value="'+data[i].orderNo+'" class="orderNo"><input type="hidden" value="'+data[i].abnormal_name+'" class="abnormal_name"><input type="hidden" value="'+data[i].createtime+'" class="createtime"><input type="hidden" value="'+data[i].id+'" class="id"><a href="javascript:void(0);" class="fl p">'+data[i].resourceName+data[i].abnormal_name+'</a><span class="fr">'+data[i].updatetime+'</span></p>'
                            mui('#mission')[0].insertAdjacentHTML('afterbegin', html);
			        };	
			    },
			    error:function(xhr,type,errorThrown){
					mui.alert(xhr,'提示') 				
				}
			});
	      	      
	      mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
	    }, 1000);
	  }
	      
	  var count = 0;
	  /*
	   * 上拉加载具体业务实现
	   */
	  function pullupRefresh() 
	  {
	    setTimeout(function() {
	      mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
	      var cells = document.body.querySelectorAll('.mission p');
	      mui.ajax({
	            type: "POST",
			    url: __PATH__+"index/news",
			    async: true,
			    data:{
			    	username:user
			    },
			    dataType: "json",
			    json: "jsoncallback",
			    timeout: 1000,
			    success: function(data) {
			    	var dialog = data;
	  			    var table = document.body.querySelector('.mission');
		            var cells = document.body.querySelectorAll('.mission p');
			        for(var i = cells.length, len = i + 3; i < len; i++){
			      	    var html = '<p><input type="hidden" value="'+data[i].updatetime+'" class="updatetime"><input type="hidden" value="'+data[i].send_member+'" class="send_member"><input type="hidden" value="'+data[i].resourceName+'" class="resourceName"><input type="hidden" value="'+data[i].orderNo+'" class="orderNo"><input type="hidden" value="'+data[i].abnormal_name+'" class="abnormal_name"><input type="hidden" value="'+data[i].createtime+'" class="createtime"><input type="hidden" value="'+data[i].id+'" class="id"><a href="javascript:void(0);" class="fl p">'+data[i].resourceName+data[i].abnormal_name+'</a><span class="fr">'+data[i].updatetime+'</span></p>'
                            mui('#mission')[0].insertAdjacentHTML('afterbegin', html);
			        };	
			    },
			    error:function(xhr,type,errorThrown){
					mui.alert(xhr,'提示') 				
				}
			});
	    }, 1000);
	  }
	      
	      
	      
	  if (mui.os.plus) {
	    mui.plusReady(function() {
	      setTimeout(function() {
	        mui('#pullrefresh').pullRefresh().pullupLoading();
	      }, 1000);
	
	    });
	  }else 
	  { 
	    mui.ready(function() {
	      mui('#pullrefresh').pullRefresh().pullupLoading();
	    });
	  }
  	
  	
</script>
</html>